home *** CD-ROM | disk | FTP | other *** search
- /*
- * FlashBeep.c
- *
- * Extension for MacHack '93 contest (Flashin' when Beepin').
- * (based on example extension provided with PatchWorks)
- *
- * Written with PatchWorks by Robert (Mouse) Herrell and Patrick Beard.
- *
- * Copyright (c) 1993 Charlie Reading. All rights reserved.
- */
-
- #include <Menus.h>
- #include <Sound.h>
- #include <string.h>
- #include <Notification.h>
- #include <Traps.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stddef.h>
-
- #include <PWExceptions.h>
- #include <Extension.h>
- #include <GenericPatch.h>
-
- static int dprintf(const char* format, ...);
-
- //
- // SysBeepPatch
- //
-
- class SysBeepPatch : public GenericPatch {
- public:
- SysBeepPatch();
- virtual void Behavior(void);
- };
-
- SysBeepPatch::SysBeepPatch()
- {
- // install the appropriate patch.
- GenericPatch::InitGenericPatch(_SysBeep, 0);
- Install();
- }
-
- void SysBeepPatch::Behavior()
- {
- short volume;
- unsigned long firstTicks;
-
- // if sound level not 0 (because system will flash it then), flash the menu bar,
- // delaying (8 ticks) so the user can catch their breath.
- GetSoundVol(&volume);
- if (volume != 0)
- {
- // Get the tick count so we can be sure when we start
- firstTicks = TickCount();
-
- // Invert the bar
- FlashMenuBar(0);
-
- // Wait until 8 ticks have elapsed (what happens when the sound is off)
- while (TickCount() - firstTicks < 8)
- ;
-
- // Invert the bar to restore it
- FlashMenuBar(0);
- }
- }
-
- //
- // Install routine. This is where you allocate your patch objects.
- // Throw an exception if something fails.
- //
-
- void Install()
- {
- short i;
- long bogus;
-
- try
- {
- // if extension succeeds, show happy icon.
- new SysBeepPatch;
- ShowIconFamily(134);
- }
- catch
- {
- // extension failed, show sad icon.
- ShowIconFamily(128);
- throw(theException);
- }
- }
-
- //
- // Remove routine. This is called when system is shutdown.
- // Perhaps this should be removed. Rob thinks it shouldn't even be
- // part of the design.
- //
-
- void Remove()
- {
- Patch::RemoveAll();
- }
-
- //
- // debugging printf.
- //
-
- static int dprintf(const char* format, ...)
- {
- va_list args;
- static char str[256];
- int count;
-
- va_start(args, format);
- count = vsprintf(str, format, args);
- va_end(args);
- DebugStr(c2pstr(str));
-
- return count;
- }
-